<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="6" :sm="8">
            <a-form-item
              label="内容"
              :maxLength="50">
              <a-input placeholder="请输入内容" v-model="queryParam.content"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item
              label="日期范围"
              :maxLength="50">
              <a-range-picker @change="onChange" v-model="queryParam.timeinfo" format="YYYY-MM-DD"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)" icon="search">查询</a-button>
              <a-button
                @click="() => {this.$objToReset(queryParam),$refs.table.refresh(true)}"
                icon="reload"
                style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>

      <s-table
        ref="table"
        rowKey="id"
        size="middle"
        :columns="columns"
        :data="loadData">
        <div
          slot="expandedRowRender"
          slot-scope="record"
          style="margin: 0">
          {{ record.datas }}
        </div>
      </s-table>
    </div>
  </a-card>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { postAction } from '@/api/manage'
  import { baseMixin } from '@/store/app-mixin'

  export default {
    name: 'LogList',
    mixins: [baseMixin],
    components: { STable, Ellipsis },
    data () {
      return {
        visible: false,
        // 查询条件
        queryParam: {
          title: ''
        },
        // 表头
        columns: [
          {
            title: '日志内容',
            dataIndex: 'content'
          },
          {
            title: '操作人',
            dataIndex: 'company_name'
          },
          {
            title: 'IP',
            dataIndex: 'ip'
          },
          {
            title: '类型',
            dataIndex: 'type_flag',
            customRender: (text) => this.$sysDictFilter(text, 'logFlag')
          },
          {
            title: '操作时间',
            dataIndex: 'create_time',
            customRender: (text) => this.$momentFormat(text, 'YYYY-MM-DD')
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          console.log('loadData.parameter', parameter)
          return postAction(this.url.list, Object.assign(parameter, this.queryParam))
            .then(res => {
              return res.result
            })
        },
        dict: '',
        url: {
          list: '/system/syslog/list'
        }
      }
    },
    computed: {},
    methods: {
      searchQuery () {
        this.$refs.table.refresh(true)
      },
      onChange (value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.times = dateString[0] + ' ~ ' + dateString[1]
      }
    },
    watch: {}
  }
</script>
<style scoped>
</style>
